#!/bin/bash

echo 
echo "开始安装>>>>>>>>>>>>>>" 
echo 
echo "更换镜像源......"

read -p "请确保当前有ROOT权限 1有 其他退出 :" is_have_root
	
if [[ $is_have_root -ne 1 ]];then
	echo "请用sudo执行..."
	exit;
fi

read -p "是否更新镜像源 1更新 其他不更新 :" is_update_yum
	
if (($is_update_yum == 1));then
    echo -e "\E[32;5m 开始更换镜像源>>>>>>> \E[0m"
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    while true;do
        read -p "请输入你的linux版本 1 centos7 2 centos6  0退出: " c_version
        
        if (($c_version == 1));then
            echo "你的版本是:centos-1"
            curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
            yum clean all
            yum makecache
            break;
        elif (($c_version == 2)); then
            echo "你的版本是:centos-2"
            curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
            yum clean all
            yum makecache
            break;
        elif (($c_version == 0)); then
            exit;
        else
            echo -e ""
            echo -e "\E[31;5m 版本输入错误,请重新输入！ \E[0m"
        fi
    done 

fi
read -p "是否安装ZSH 1安装 其他不安装 :" is_install_zsh
	
if (($is_install_zsh == 1));then
	echo -e "\E[32;5m 开始安装ZSH>>>>>>> \E[0m"
	yum -y install zsh

	yum -y install git
	
	cd ${HOME}
	
	git clone https://gitee.com/dongzhe3917875/oh-my-zsh.git
	cd ${HOME}/oh-my-zsh/tools
	
	sed -i "s/env zsh/echo ''/g" install.sh
	sh install.sh
	
	git clone https://gitee.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

	git clone https://gitee.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

	
	cd ${HOME}
	
	echo "修改 .zshrc 文件...."
	echo ""
	rm -f ${HOME}/.zshrc

	touch ${HOME}/.zshrc

	echo "# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
#
# Path to your oh-my-zsh installation.
  
source /etc/profile
export ZSH=/root/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of
# looking in ~/.oh-my-zsh/themes/
# An empty array have no effect
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
">> ${HOME}/.zshrc

	echo "plugins=(">> ${HOME}/.zshrc
	echo "  git ,">> ${HOME}/.zshrc
	echo "  zsh-autosuggestions ,">> ${HOME}/.zshrc
	echo "  zsh-syntax-highlighting">> ${HOME}/.zshrc
	echo ")">> ${HOME}/.zshrc
	echo 'source $ZSH/oh-my-zsh.sh'>> ${HOME}/.zshrc
	echo "# xshell 问题">> ${HOME}/.zshrc
	echo "bindkey '\e[1~' beginning-of-line">> ${HOME}/.zshrc
	echo "bindkey '\e[4~' end-of-line">> ${HOME}/.zshrc
	echo "# 自定义命令Custom command">> ${HOME}/.zshrc
fi
echo
echo
echo
cd ${HOME}

echo "安装vim....."
yum -y install vim

echo "安装zip....."
yum -y install zip
yum -y install unzip
yum -y install wget

echo
echo
echo
read -p "是否安装宝塔 1安装 其他不安装 :" is_install_bt

if (($is_install_bt == 1));then
	wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
	rm -rf install.sh
	bt 16
fi


if [ -f "${HOME}/.my-alias" ]; then

    echo "${HOME}/.my-alias 已存在！"
else
    echo "生成自定义集合！"
    touch ${HOME}/.my-alias
    echo '#!/usr/bash'>> ${HOME}/.my-alias
    echo "alias cls='clear'" >> ${HOME}/.my-alias
    echo 'source ${HOME}/.my-alias' >> /etc/profile
    echo "自定义命令集合：${HOME}/.my-alias"
fi


echo -e "\E[32;5m 安装完成！>>>>>>> \E[0m"

env zsh
